<?php 
class SupplierAction extends Action{
	public function index(){
		$this->display();
	}
	public function supplier_list(){
		$supplier = M('supplier'); // 实例化Data数据模型
		$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
		$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 20;
		$offset = ($page-1)*$rows;
		$result = array();
		$row = mysql_fetch_assoc(mysql_query("select count(*) As Total from `supplier`"));
		$result['total'] = $row['Total'];
		$items = $supplier->order('id DESC')->limit("$offset,$rows")->select();
		$result['rows'] = $items;
		echo json_encode($result);
	}
	public function supplier_save(){
		$name = $_REQUEST['name'];
		$qq = $_REQUEST['qq'];
		$tel = $_REQUEST['tel'];
		$mobile = $_REQUEST['mobile'];
		$address = $_REQUEST['address'];
		$wangwang = $_REQUEST['wangwang'];
		$date = date('Y-m-j');
		$Supplier = M('supplier');
		$sql = "insert into supplier(name,qq,tel,mobile,address,wangwang,date) values('$name','$qq','$tel','$mobile','$address','$wangwang','$date')";
		@mysql_query($sql);
		echo json_encode(array(
				'id' => mysql_insert_id(),
				'name' => $name,
				'qq' => $qq,
				'tel' => $tel,
				'mobile' => $mobile,
				'address' => $address,
				'wangwang' => $wangwang,
				'date' => $date
		));
	}
	public function supplier_update(){
		$id = intval($_REQUEST['id']);
		$data['name'] = $_REQUEST['name'];
		$data['qq'] = $_REQUEST['qq'];
		$data['tel'] = $_REQUEST['tel'];
		$data['mobile'] = $_REQUEST['mobile'];
		$data['address'] = $_REQUEST['address'];
		$data['wangwang'] = $_REQUEST['wangwang'];
		$data['date'] = $_REQUEST['date'];
		$Supplier = M('supplier');
		$Supplier->where("id=$id")->save($data);
		echo json_encode(array(
				'id' => $id,
				'name' => $name,
				'qq' => $qq,
				'tel' => $tel,
				'mobile' => $mobile,
				'address' => $address,
				'wangwang' => $wangwang,
				'date' => $date
		));
	}
	public function supplier_destroy(){
		$id = intval($_REQUEST['id']);
		$Supplier = M('supplier');
		$Supplier->where("id=$id")->delete();
		@mysql_query($sql);
		echo json_encode(array('success'=>true));
	}
}
?>